package com.tudouji.project.flow.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.project.flow.domain.Smsrule;
import com.tudouji.project.flow.service.ISmsruleService;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.web.page.TableDataInfo;

/**
 * 消息发送规则Controller
 * 
 * @author tudouji
 * @date 2021-05-20
 */
@RestController
@RequestMapping("/flow/smsrule")
public class SmsruleController extends BaseController
{
    @Autowired
    private ISmsruleService smsruleService;

    /**
     * 查询消息发送规则列表
     */
    @PreAuthorize("@ss.hasPermi('flow:smsrule:list')")
    @GetMapping("/list")
    public TableDataInfo list(Smsrule smsrule)
    {
        startPage();
        List<Smsrule> list = smsruleService.selectSmsruleList(smsrule);
        return getDataTable(list);
    }

    /**
     * 导出消息发送规则列表
     */
    @PreAuthorize("@ss.hasPermi('flow:smsrule:export')")
    @Log(title = "消息发送规则", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Smsrule smsrule)
    {
        List<Smsrule> list = smsruleService.selectSmsruleList(smsrule);
        ExcelUtil<Smsrule> util = new ExcelUtil<Smsrule>(Smsrule.class);
        return util.exportExcel(list, "smsrule");
    }

    /**
     * 获取消息发送规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('flow:smsrule:query')")
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") String guid)
    {
        return AjaxResult.success(smsruleService.selectSmsruleById(guid));
    }

    /**
     * 新增消息发送规则
     */
    @PreAuthorize("@ss.hasPermi('flow:smsrule:add')")
    @Log(title = "消息发送规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Smsrule smsrule)
    {
        return toAjax(smsruleService.insertSmsrule(smsrule));
    }

    /**
     * 修改消息发送规则
     */
    @PreAuthorize("@ss.hasPermi('flow:smsrule:edit')")
    @Log(title = "消息发送规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Smsrule smsrule)
    {
        return toAjax(smsruleService.updateSmsrule(smsrule));
    }

    /**
     * 删除消息发送规则
     */
    @PreAuthorize("@ss.hasPermi('flow:smsrule:remove')")
    @Log(title = "消息发送规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids)
    {
        return toAjax(smsruleService.deleteSmsruleByIds(guids));
    }


    @GetMapping("/getSmsrule")
    public AjaxResult getSmsrule(Smsrule smsrule)
    {
        List<Smsrule> list = smsruleService.selectSmsruleList(smsrule);
        return AjaxResult.success(list);
    }
}
